package test4

object ArrayMax {
  def main(args: Array[String]): Unit = {
    val l = Array(1, 2, 5, 6, 12, 6, 45, 3, 77, 33, 76, 55)
    println(l)
    var max = l.reduceLeft((a, b) => {
      if (a > b) a else b
    })
    println(max)
    println(">>>>>>>>>>>>>>>>>>")
    var fm = largest(x =>10*x- x * x, -10 to 10)
    println(fm)
  }

  def largest(fun: (Int) => Int, y: Seq[Int]): Int = {
//    y.reduceLeft((a, b) => {
//      if (fun(a) > fun(b)) fun(a) else fun(b)
//    })
   y.map(fun).max
//    y.reduceLeft((a, b) => {
//     if(a>b)a else b
//
//      //if (fun(a) > fun(b)) fun(a) else fun(b)
//      //if (fun(a) > fun(b)) a else b
//    })
    //if (fun(a) > fun(b)) a else b
  }
}
